package com.atguigu.scala_01.chapter_03_IO

import java.io.{BufferedReader, ByteArrayInputStream, InputStreamReader, ObjectInputStream}
import java.net.{ServerSocket, Socket}

object Server {
  def main(args: Array[String]): Unit = {
    val server = new ServerSocket(12345)
    while (true) {
      val socket: Socket = server.accept()
      val reader = new BufferedReader(new InputStreamReader(socket.getInputStream, "UTF-8"))

      val array:String= reader.readLine()

      println(array)

//      val value: Func = deserialize(array)
//      println(value.double(2))
    }
  }

  def deserialize[Func](bytes: Array[Byte]): Func = {
    val bis = new ByteArrayInputStream(bytes)
    val ois = new ObjectInputStream(bis)
    ois.readObject.asInstanceOf[Func] //进行类型转换，因为你要返回这个类型
  }

}
